package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.MessageService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.SelectMessageListVo;
import com.rm.zeyou.vo.response.SelectMessageListResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 消息表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-13 09:51:59
 */
@Api(tags = "用户消息相关")
@RestController
@RequestMapping("/api/message")
public class MessageController {
    @Resource
    private MessageService messageService;
    @Resource
    private LoginUtil loginUtil;

    @ApiOperation(value = "查询消息列表")
    @PostMapping("selectMessageList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<SelectMessageListResponseVo>> selectMessageList(@RequestBody SelectMessageListVo requestVo) {
        User user = loginUtil.getUser();
        return  messageService.selectMessageList(user,requestVo);
    }


    @ApiOperation(value = "读取消息")
    @GetMapping("readMessage")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> readMessage(@RequestParam Long messageId) {
        User user = loginUtil.getUser();
        return  messageService.readMessage(user,messageId);
    }

    @ApiOperation(value = "一键删除消息")
    @PostMapping("deleteMessage")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> deleteMessage() {
        User user = loginUtil.getUser();
        return  messageService.deleteMessage(user);
    }

}
